"use strict";
const common_vendor = require("../../common/vendor.js");
const api_index = require("../../api/index.js");
const api_community_index = require("../../api/community/index.js");
const api_user = require("../../api/user.js");
const stores_userInfo = require("../../stores/userInfo.js");
const common_assets = require("../../common/assets.js");
if (!Array) {
  const _easycom_up_radio2 = common_vendor.resolveComponent("up-radio");
  const _easycom_up_radio_group2 = common_vendor.resolveComponent("up-radio-group");
  const _easycom_up_form_item2 = common_vendor.resolveComponent("up-form-item");
  const _component_ocr_navigator = common_vendor.resolveComponent("ocr-navigator");
  const _easycom_up_input2 = common_vendor.resolveComponent("up-input");
  const _easycom_up_form2 = common_vendor.resolveComponent("up-form");
  const _easycom_up_checkbox2 = common_vendor.resolveComponent("up-checkbox");
  const _easycom_up_icon2 = common_vendor.resolveComponent("up-icon");
  const _easycom_up_popup2 = common_vendor.resolveComponent("up-popup");
  const _easycom_up_action_sheet2 = common_vendor.resolveComponent("up-action-sheet");
  const _easycom_up_toast2 = common_vendor.resolveComponent("up-toast");
  (_easycom_up_radio2 + _easycom_up_radio_group2 + _easycom_up_form_item2 + _component_ocr_navigator + _easycom_up_input2 + _easycom_up_form2 + _easycom_up_checkbox2 + _easycom_up_icon2 + _easycom_up_popup2 + _easycom_up_action_sheet2 + _easycom_up_toast2)();
}
const _easycom_up_radio = () => "../../node-modules/uview-plus/components/u-radio/u-radio.js";
const _easycom_up_radio_group = () => "../../node-modules/uview-plus/components/u-radio-group/u-radio-group.js";
const _easycom_up_form_item = () => "../../node-modules/uview-plus/components/u-form-item/u-form-item.js";
const _easycom_up_input = () => "../../node-modules/uview-plus/components/u-input/u-input.js";
const _easycom_up_form = () => "../../node-modules/uview-plus/components/u-form/u-form.js";
const _easycom_up_checkbox = () => "../../node-modules/uview-plus/components/u-checkbox/u-checkbox.js";
const _easycom_up_icon = () => "../../node-modules/uview-plus/components/u-icon/u-icon.js";
const _easycom_up_popup = () => "../../node-modules/uview-plus/components/u-popup/u-popup.js";
const _easycom_up_action_sheet = () => "../../node-modules/uview-plus/components/u-action-sheet/u-action-sheet.js";
const _easycom_up_toast = () => "../../node-modules/uview-plus/components/u-toast/u-toast.js";
if (!Math) {
  (_easycom_up_radio + _easycom_up_radio_group + _easycom_up_form_item + _easycom_up_input + _easycom_up_form + _easycom_up_checkbox + _easycom_up_icon + _easycom_up_popup + _easycom_up_action_sheet + _easycom_up_toast)();
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "register",
  setup(__props) {
    const userInfoStore = stores_userInfo.useUserInfoStore();
    const uToastRef = common_vendor.ref(null);
    const uForm = common_vendor.ref(null);
    const data = common_vendor.reactive({
      showCommunity: false,
      communitys: [],
      showStreet: false,
      streets: [],
      showPlot: false,
      plots: [],
      showBuild: false,
      buildings: [],
      form: {
        userName: void 0,
        idCard: void 0,
        phonenumber: userInfoStore.userInfo.wxPhone,
        region: "北碚区",
        street: "朝阳街道",
        communityId: void 0,
        communityName: void 0,
        subdistrict: "",
        //所属小区
        subdistrictId: "",
        building: void 0,
        buildingId: void 0,
        openId: userInfoStore.userInfo.wxOpenId,
        vxPhone: userInfoStore.userInfo.wxPhone,
        residenceStatus: 0,
        alleyName: void 0,
        alleyId: void 0,
        house: ""
      },
      rules: {
        residenceStatus: {
          type: "number",
          required: true,
          message: "请选择类型",
          trigger: ["blur", "change"]
        },
        userName: {
          type: "string",
          required: true,
          message: "请填写姓名",
          trigger: ["blur", "change"]
        },
        idCard: [
          {
            type: "string",
            required: true,
            message: "请填写身份证号",
            trigger: ["blur", "change"]
          },
          {
            validator: (rule, value, callback) => {
              return common_vendor.index.$u.test.idCard(value);
            },
            message: "身份证号不正确",
            trigger: ["change", "blur"]
          }
        ],
        phonenumber: [
          {
            type: "string",
            required: true,
            message: "请填写手机号码",
            trigger: ["blur", "change"]
          },
          {
            validator: (rule, value, callback) => {
              return common_vendor.index.$u.test.mobile(value);
            },
            message: "手机号码不正确",
            trigger: ["change", "blur"]
          }
        ],
        communityId: {
          type: "number",
          required: true,
          message: "居住地请选择所属社区",
          trigger: ["blur", "change"]
        },
        buildingId: {
          type: "number",
          required: true,
          message: "居住地请选择门楼牌号",
          trigger: ["blur", "change"]
        }
      },
      isAgree: false
    });
    const {
      showCommunity,
      communitys,
      showStreet,
      streets,
      showPlot,
      plots,
      showBuild,
      buildings,
      form,
      rules,
      isAgree
    } = common_vendor.toRefs(data);
    const showTip = common_vendor.ref(false);
    const timer = common_vendor.ref(null);
    const communitySelect = (e) => {
      form.value.communityName = e.name;
      form.value.communityId = e.id;
      resetData(1);
      getAlleyList();
    };
    const streetSelect = (e) => {
      form.value.alleyName = e.name;
      form.value.alleyId = e.id;
      resetData(2);
      getPlotList();
      getBuildingList();
    };
    const plotSelect = (e) => {
      form.value.subdistrict = e.name;
      form.value.subdistrictId = e.id;
      resetData(3);
      getBuildingList();
    };
    const buildSelect = (e) => {
      form.value.building = e.name;
      form.value.buildingId = e.id;
    };
    const getCommunityList = () => {
      api_community_index.communityGroup().then((res) => {
        const { data: data2 } = res;
        communitys.value = data2 ?? [];
      }).catch((err) => {
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    const getAlleyList = () => {
      api_community_index.selectAlleyList({ communityId: form.value.communityId }).then((res) => {
        const { data: data2 } = res;
        streets.value = data2 ?? [];
        if (streets.value.length) {
          streets.value = streets.value.map((item) => {
            item.name = item.alleyName;
            return item;
          });
        }
      }).catch((err) => {
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    const getPlotList = () => {
      api_community_index.selectSubdistrictList({ alleyId: form.value.alleyId }).then((res) => {
        const { data: data2 } = res;
        plots.value = data2 ?? [];
        if (plots.value.length) {
          plots.value = plots.value.map((item) => {
            item.name = item.subdistrictName;
            return item;
          });
        }
      }).catch((err) => {
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    const getBuildingList = () => {
      api_community_index.selectBuildingList({
        alleyId: form.value.alleyId,
        subId: form.value.subdistrictId
      }).then((res) => {
        const { data: data2 } = res;
        buildings.value = data2 ?? [];
        if (buildings.value.length) {
          buildings.value = buildings.value.map((item) => {
            item.name = item.buildingName;
            return item;
          });
        }
      }).catch((err) => {
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    const resetData = (type) => {
      if (type <= 1) {
        form.value.alleyName = "";
        form.value.alleyId = "";
      }
      if (type <= 2) {
        form.value.subdistrict = "";
        form.value.subdistrictId = "";
      }
      if (type <= 3) {
        form.value.building = "";
        form.value.buildingId = "";
      }
    };
    const idCardOcr = (e) => {
      console.log(e);
      if (e.detail) {
        form.value.idCard = e.detail.id.text;
        form.value.userName = e.detail.name.text;
      }
    };
    const onsubmit = () => {
      uForm.value.validate().then((res) => {
        if (isAgree.value) {
          common_vendor.index.showLoading({
            title: "提交中",
            mask: true
          });
          api_index.crowdRegister(form.value).then(async (res1) => {
            common_vendor.index.hideLoading();
            const { data: data2 } = res1;
            await userInfoStore.setToken(data2.token);
            await userInfoStore.setUserInfo(data2);
            await getCrowdUserInfo();
            showTip.value = true;
            if (timer)
              clearTimeout(timer);
            timer.value = setTimeout(() => {
              close();
              clearTimeout(timer);
            }, 3e3);
          }).catch((err) => {
            common_vendor.index.hideLoading();
            uToastRef.value.show({
              type: "error",
              message: err
            });
          });
        } else {
          common_vendor.index.$u.toast("请先同意服务协议及隐私协议");
        }
      }).catch(() => {
      });
    };
    const getCrowdUserInfo = () => {
      api_user.crowdUserInfo({ crowdUserId: userInfoStore.userInfo.userId }).then((res) => {
        const { data: data2 } = res;
        userInfoStore.setCrowdInfo(data2);
      }).catch((err) => {
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    const close = () => {
      showTip.value = false;
      common_vendor.index.redirectTo({
        url: "/pages/crowd/home/index"
      });
    };
    const getLocation = () => {
      common_vendor.index.getLocation({
        type: "gcj02",
        success: function(res) {
          api_user.getCommunityByPoint({ lat: res.latitude, lnt: res.longitude }).then((res1) => {
            const { data: data2 } = res1;
            if (data2.withinFenceStatus) {
              form.value.communityName = data2.communityName;
              form.value.communityId = data2.communityId;
            }
          }).catch((err) => {
            uToastRef.value.show({
              type: "error",
              message: err
            });
          });
        },
        fail: function(err) {
          uToastRef.value.show({
            type: "error",
            message: "当前位置信息获取失败"
          });
        }
      });
    };
    common_vendor.onLoad(() => {
      getCommunityList();
      getLocation();
    });
    common_vendor.onReady(() => {
      uForm.value.setRules(rules.value);
    });
    return (_ctx, _cache) => {
      return {
        a: common_vendor.p({
          activeColor: "#0189FE",
          name: 0,
          label: "常住"
        }),
        b: common_vendor.p({
          activeColor: "#0189FE",
          name: 1,
          label: "暂住"
        }),
        c: common_vendor.o(($event) => common_vendor.unref(form).residenceStatus = $event),
        d: common_vendor.p({
          placement: "row",
          modelValue: common_vendor.unref(form).residenceStatus
        }),
        e: common_vendor.p({
          label: "类型：",
          prop: "residenceStatus"
        }),
        f: common_vendor.unref(common_assets.idcardRead),
        g: common_vendor.o(idCardOcr),
        h: common_vendor.o(($event) => common_vendor.unref(form).userName = $event),
        i: common_vendor.p({
          border: "surround",
          color: "#000000",
          placeholder: "请输入姓名",
          placeholderStyle: "{color: '#707070'}",
          clearable: true,
          modelValue: common_vendor.unref(form).userName
        }),
        j: common_vendor.p({
          label: "姓名：",
          prop: "userName"
        }),
        k: common_vendor.o(($event) => common_vendor.unref(form).idCard = $event),
        l: common_vendor.p({
          border: "surround",
          color: "#000000",
          placeholder: "请输入身份证号码",
          placeholderStyle: "{color: '#707070'}",
          type: "idcard",
          clearable: true,
          modelValue: common_vendor.unref(form).idCard
        }),
        m: common_vendor.p({
          label: "身份证号：",
          prop: "idCard"
        }),
        n: common_vendor.o(($event) => common_vendor.unref(form).phonenumber = $event),
        o: common_vendor.p({
          border: "surround",
          color: "#000000",
          placeholder: "请输入手机号",
          placeholderStyle: "{color: '#707070'}",
          clearable: true,
          modelValue: common_vendor.unref(form).phonenumber
        }),
        p: common_vendor.p({
          label: "手机号：",
          prop: "phonenumber"
        }),
        q: common_vendor.o(($event) => common_vendor.unref(form).region = $event),
        r: common_vendor.p({
          border: "none",
          color: "#707070",
          disabled: true,
          modelValue: common_vendor.unref(form).region
        }),
        s: common_vendor.o(($event) => common_vendor.unref(form).street = $event),
        t: common_vendor.p({
          border: "none",
          color: "#707070",
          disabled: true,
          modelValue: common_vendor.unref(form).street
        }),
        v: common_vendor.o(($event) => common_vendor.unref(form).communityName = $event),
        w: common_vendor.p({
          placeholder: "社区名称",
          border: "none",
          disabled: true,
          disabledColor: "#ffffff",
          placeholderStyle: "{color: '#707070'}",
          suffixIcon: "arrow-down",
          suffixIconStyle: {
            color: "#777777",
            fontSize: "20rpx"
          },
          modelValue: common_vendor.unref(form).communityName
        }),
        x: common_vendor.o(($event) => showCommunity.value = true),
        y: common_vendor.p({
          label: "居住地：",
          prop: "communityId"
        }),
        z: common_vendor.o(($event) => common_vendor.unref(form).alleyName = $event),
        A: common_vendor.p({
          placeholder: "街路巷",
          border: "none",
          disabled: true,
          disabledColor: "#ffffff",
          placeholderStyle: "{color: '#707070'}",
          suffixIcon: "arrow-down",
          suffixIconStyle: {
            color: "#777777",
            fontSize: "20rpx"
          },
          modelValue: common_vendor.unref(form).alleyName
        }),
        B: common_vendor.o(($event) => showStreet.value = true),
        C: common_vendor.o(($event) => common_vendor.unref(form).building = $event),
        D: common_vendor.p({
          placeholder: "门楼牌号",
          border: "none",
          disabled: true,
          disabledColor: "#ffffff",
          placeholderStyle: "{color: '#707070'}",
          suffixIcon: "arrow-down",
          suffixIconStyle: {
            color: "#777777",
            fontSize: "20rpx"
          },
          modelValue: common_vendor.unref(form).building
        }),
        E: common_vendor.o(($event) => showBuild.value = true),
        F: common_vendor.p({
          label: "    ",
          prop: "buildingId"
        }),
        G: common_vendor.o(($event) => common_vendor.unref(form).house = $event),
        H: common_vendor.p({
          border: "none",
          color: "#000000",
          placeholder: "输入户号 例如:1-1",
          placeholderStyle: "{color: '#707070'}",
          clearable: true,
          modelValue: common_vendor.unref(form).house
        }),
        I: common_vendor.p({
          label: "    "
        }),
        J: common_vendor.sr(uForm, "97bb96ad-0", {
          "k": "uForm"
        }),
        K: common_vendor.p({
          labelPosition: "left",
          model: common_vendor.unref(form),
          rules: common_vendor.unref(rules),
          labelWidth: "85",
          labelAlign: "right"
        }),
        L: common_vendor.o(($event) => common_vendor.isRef(isAgree) ? isAgree.value = $event : null),
        M: common_vendor.p({
          label: "我已认真阅读并同意《用户服务协议》及《隐私协议》",
          name: "agree",
          usedAlone: true,
          checked: common_vendor.unref(isAgree)
        }),
        N: common_vendor.o(onsubmit),
        O: common_vendor.p({
          name: "checkmark-circle-fill",
          color: "#33A954",
          size: "70"
        }),
        P: common_vendor.p({
          show: common_vendor.unref(showTip),
          round: 8,
          mode: "center"
        }),
        Q: common_vendor.o(($event) => showCommunity.value = false),
        R: common_vendor.o(communitySelect),
        S: common_vendor.p({
          show: common_vendor.unref(showCommunity),
          actions: common_vendor.unref(communitys),
          title: "请选择社区"
        }),
        T: common_vendor.o(($event) => showStreet.value = false),
        U: common_vendor.o(streetSelect),
        V: common_vendor.p({
          show: common_vendor.unref(showStreet),
          actions: common_vendor.unref(streets),
          title: "请选择街路巷"
        }),
        W: common_vendor.o(($event) => showPlot.value = false),
        X: common_vendor.o(plotSelect),
        Y: common_vendor.p({
          show: common_vendor.unref(showPlot),
          actions: common_vendor.unref(plots),
          title: "请选择小区"
        }),
        Z: common_vendor.o(($event) => showBuild.value = false),
        aa: common_vendor.o(buildSelect),
        ab: common_vendor.p({
          show: common_vendor.unref(showBuild),
          actions: common_vendor.unref(buildings),
          title: "请选择门楼牌号"
        }),
        ac: common_vendor.sr(uToastRef, "97bb96ad-28", {
          "k": "uToastRef"
        })
      };
    };
  }
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-97bb96ad"]]);
wx.createPage(MiniProgramPage);
